package com.ha.web.controller.system.house.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ha.common.annotation.Log;
import com.ha.common.enums.BusinessType;
import com.ha.system.house.domain.HaHouseInfo;
import com.ha.system.house.service.IHaHouseInfoService;
import com.ha.common.core.controller.BaseController;
import com.ha.common.core.domain.AjaxResult;
import com.ha.common.utils.poi.ExcelUtil;
import com.ha.common.core.page.TableDataInfo;

/**
 * 房屋信息Controller
 */
@Controller
@RequestMapping("/house/house")
public class HaHouseInfoController extends BaseController {
    private String prefix = "house/house";

    @Autowired
    private IHaHouseInfoService haHouseInfoService;

    @RequiresPermissions("house:house:view")
    @GetMapping()
    public String house() {
        return prefix + "/house";
    }

    /**
     * 查询房屋信息列表
     */
    @RequiresPermissions("house:house:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HaHouseInfo haHouseInfo) {
        startPage();
        List<HaHouseInfo> list = haHouseInfoService.selectHaHouseInfoList(haHouseInfo);
        return getDataTable(list);
    }

    /**
     * 导出房屋信息列表
     */
    @RequiresPermissions("house:house:export")
    @Log(title = "房屋信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HaHouseInfo haHouseInfo) {
        List<HaHouseInfo> list = haHouseInfoService.selectHaHouseInfoList(haHouseInfo);
        ExcelUtil<HaHouseInfo> util = new ExcelUtil<HaHouseInfo>(HaHouseInfo.class);
        return util.exportExcel(list, "house");
    }

    /**
     * 新增房屋信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存房屋信息
     */
    @RequiresPermissions("house:house:add")
    @Log(title = "房屋信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HaHouseInfo haHouseInfo) {
        return toAjax(haHouseInfoService.insertHaHouseInfo(haHouseInfo));
    }

    /**
     * 修改房屋信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        HaHouseInfo haHouseInfo = haHouseInfoService.selectHaHouseInfoById(id);
        mmap.put("haHouseInfo", haHouseInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存房屋信息
     */
    @RequiresPermissions("house:house:edit")
    @Log(title = "房屋信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HaHouseInfo haHouseInfo) {
        return toAjax(haHouseInfoService.updateHaHouseInfo(haHouseInfo));
    }

    /**
     * 删除房屋信息
     */
    @RequiresPermissions("house:house:remove")
    @Log(title = "房屋信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(haHouseInfoService.deleteHaHouseInfoByIds(ids));
    }
}
